# -*- coding: utf-8 -*-
# @Time    : 2019/2/22 9:21
# @Author  : cj
# @File    : bounding_box.py
import math

from dataset.point import Point

base_anchor_size = [256, 256]


class BoundingBox:
    """
    对于BoundingBox的四个点坐标进行的操作，形如[upper_left,bottom_right]
    """

    def __init__(self, upper_left: Point, bottom_right: Point):
        self._upper_left = upper_left
        self._bottom_right = bottom_right
        self._height = bottom_right.y - upper_left.y
        self._width = bottom_right.x - upper_left.x

    def get_scale(self):
        """
        计算scale
        :return: 根号（boundxing_box的面积/base_anchor的面积）
        """
        return math.sqrt(float(self._height * self._width) / (base_anchor_size[0] * base_anchor_size[1]))

    def get_aspect_ratio(self):
        """
        辅助aspect_ratio的计算
        :return: 返回width/height
        """
        if self._height == 0:
            raise ValueError("height can't be zero")
        return float(self._width) / self._height

    def get_upper_left(self):
        """
        :return: 返回upper_left
        """
        return self._upper_left

    def get_bottom_right(self):
        """
        :return: 返回bottom_right
        """
        return self._bottom_right

    def get_height(self):
        """
        :return: 返回boundingbox的高
        """
        return self._height

    def get_width(self):
        """
        :return: 返回boundingbox的宽
        """
        return self._width

    def set_upper_left(self, upper_left: Point):
        """
        函数用于设置upper_left
        :param upper_left: 更改后的upper_left的值
        """
        self._upper_left = upper_left

    def set_bottom_right(self, bottom_right: Point):
        """
        函数用于设置bottom_right
        :param bottom_right: 更改后的bottom_right的值
        """
        self._bottom_right = bottom_right
